<%@ include file="/common/taglibs.jsp" %>

<head>
    <title><fmt:message key="message.from.admin.title"/></title>
    <meta name="menu" content="AdminMenu"/>
</head>
<body id="info">

<div>
    <h2><fmt:message key="message.from.admin.heading"/></h2>

    <p><fmt:message key="message.from.admin.message"/></p>

 	<s:form cssClass="well form-horizontal" autocomplete="off">
 		
		<s:textarea key="message.from.admin.text" id="message" name="message" rows="6" style="width:100%"></s:textarea>
		<s:checkbox key="message.from.admin.login" id="login" name="login"></s:checkbox>
	
	<div id="actions" class="form-actions">
		<div onclick="saveMessage();" class="btn btn-primary">
				<i class="icon-plus icon-white"></i>
	            <fmt:message key="button.save"/>
		</div>
		<div onclick="clearMessage();" class="btn btn-primary">
	            <i class="icon-upload icon-white"></i>
	            <fmt:message key="button.clear"/>
	    </div>
	</div>
 	</s:form>
 
</div>
<script type="text/javascript">
	
	function saveMessage() {
		if(confirm('<fmt:message key="message.from.admin.confirm.save" />')) {			
			DwrService.writeMessageFromAdmin($('#message').val(), $('#login').is(':checked'));
			$('#spanMessageFromAdmin').text($('#message').val());
		  	$('#messageFromAdmin').show();
		  	loadingoff();
		}
	}
	
	function clearMessage() {
		if(confirm('<fmt:message key="message.from.admin.confirm.clear" />')) {				
			DwrService.writeMessageFromAdmin(null, false);
			$('#spanMessageFromAdmin').text("");
		  	$('#messageFromAdmin').hide();
		  	$('#message').val("");
		  	$('#login').prop( "checked", false );
		  	loadingoff();
		}
	}
	
	DwrService.getMessageFromAdmin({
		  callback:function(obj) {
				  if(obj.message != null) {					  
				  	  $('#message').text(obj.message);
				  }
				  if(obj.login != null) {					  
				  	  $('#login').prop( "checked", obj.login );
				  }
				  loadingoff();
			 }  
	});
	
</script>
</body>
